package com.baidu.mapper;

import com.baidu.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author Mawq
 * @Date 2021/8/27 10:48
 * @Version 1.0
 */
@Mapper
public interface UserMapper {

    @Select("SELECT * FROM user")
    @Results(id = "userMapp",value = {
            @Result(property = "sex", column = "sex"),
            @Result(property = "username", column = "username"),
            @Result(property = "nickName", column = "nick_name")
    })
    public List<User> getAll();

    @Select("SELECT * FROM user where id= #{id}")
    /**
     *@ResultMap("userMapp")
     * 实现对@Result 的复用
     */
    @ResultMap("userMapp")
    public User getUserById(long id);

    @Insert("INSERT INTO user(username,nick_name,sex) VALUES(#{username}, #{nickName}, #{sex})")
    public int save(Map<String,Object> map);

    @Update("UPDATE user SET username=#{username},nick_name=#{nickName} WHERE id =#{id}")
    public int update(Map<String,Object> map);


    @Delete("DELETE FROM user WHERE id =#{id}")
    public int delete(long id);
}
